home *** CD-ROM | disk | FTP | other *** search
/ CD-ROM Data 2002 May / CD Rom Data Mayıs 2002.iso / Freeware / Blitz Basic / data1.cab / Support / help / samples / twilzone.bb < prev    next >
Encoding:
Text File  |  2002-04-10  |  5.8 KB  |  133 lines

  1. ;--------------------------------------------------------------------------
  2. ;                                                                rno 010800
  3. ;                                                         noospot42@f2s.com
  4. ;
  5. ; don't ask me what it does, I took the formula from under a nice picture 
  6. ; in a book (pictures of chaos something) and made it on amiga blitz but 
  7. ; ages are needed to get one frame on my amiga, I was curious of the result
  8. ; with litle more cpu/fpu power... :)
  9. ; use debug off 
  10. ; BlitzDemo 1.1
  11. ;--------------------------------------------------------------------------
  12. Print "Welcome to the twilight zone :)"
  13. Print ""
  14. Print ""
  15. Print "for each 'seed' point of the grid ,"
  16. Print "         do this n time  ( n=50 ) :"    ; n is itr
  17. Print ""
  18. Print "   f(x) = xold - t * ( Sin( xold + sin( 3*yold ) ) ) "
  19. Print "   f(y) = yold + t * ( Sin( yold + sin( 3*xold ) ) ) "
  20. Print ""
  21. Print " [   ESC ]     quit"
  22. Print " [    Up ]     zoom"
  23. Print " [  Down ]     unzoom"
  24. Print " [  Left ]     increase t"
  25. Print " [ Right ]     decrease t"
  26. Print " [ Pg Up ]     increase number of seeds"
  27. Print " [ Pg Dn ]     decrease number of seeds"
  28. Print ""
  29. Print " press a key..."
  30. WaitKey()
  31.  
  32. ;--------------------------------------------------------------------------
  33.  Const dwidth = 1024              ;display width
  34. Const dheight = 768              ;display height
  35.     Const nbc = 256               ;number of values for rgb
  36.    Const drs% = dheight/2         ;max square resolution display 
  37.          res# = 10                ;seeds points number (per row)
  38.    Const itr% = 50                ;iterations maximum (length of branches)
  39.     Const xc% = 0                 ;center x value
  40.     Const yc% = 0                 ;center y value
  41.           ti# = 8                 ;(bnd*2)/res     ;increment constant (seeds points)
  42.            z# = 8                 ;z will pass boundaries values (zoom)
  43.            t# =.1                 ;function factor
  44. Const deg_fac#=180/Pi             ;used by deg function
  45. Const rad_fac#=Pi/180             ;used by rad function
  46.      refresh% = 1                 ;wether screen refresh is needed (1) or not (0)
  47. Print " Go!!"
  48. ;-Main---------------------------------------------------------------------
  49. Graphics dwidth,dheight           ;enter graphic mode  
  50. SetBuffer BackBuffer()            ;use 'no hassle' double buffering :)     
  51. Origin dwidth/2,dheight/2         ;set the 0,0 point for drawing to middle of screen
  52.  
  53.  While Not KeyDown(1)             ;While not [ESC]
  54.  
  55.     If KeyDown(200)               ;if up arrow
  56.       z = .98*z                   ;zoom 
  57.       refresh=1                   ;need refresh
  58.     EndIf
  59.     If KeyDown(208)               ;if down arrow
  60.       z = z/.98                   ;unzoom
  61.        refresh=1
  62.     EndIf
  63.     If KeyDown(203)               ;if left arrow
  64.       t = t+.01                   ;increase t 
  65.       refresh=1
  66.     EndIf
  67.     If KeyDown(205)               ;if right arrow
  68.       t = t-.01                   ;decrease t
  69.       refresh=1
  70.     EndIf
  71.     If KeyDown(201)               ;if page up
  72.       res = res+1                 ;increase res 
  73.       refresh=1
  74.     EndIf
  75.     If KeyDown(209)               ;if page down
  76.       res = res-1                 ;decrease res
  77.       If res<=1 Then res=1        ;to avoid division by zero in frame function
  78.       refresh=1
  79.     EndIf
  80.  
  81.     If refresh=1                  ;check if any refresh is needed
  82.       Cls                         ;delete curent buffer
  83.       refresh = 0                      
  84.       doit(z,t,res)               ;calc a frame
  85.       Flip                        ;flip drawbuffer
  86.     EndIf
  87.  Wend
  88. EndGraphics                       ;quit graphic mode
  89. End                               ;bye
  90. ;--------------------------------------------------------------------------
  91. Function doit(bnd#,t#,res#)
  92.  Local i%                         ;iteration counter 
  93.  Local xb# = bnd                  ;x boundaries
  94.  Local yb# = bnd                  ;y boundaries
  95.  Local df# = drs/bnd              ;display factor  
  96.  Local xi# = xc-xb                ;initial value of x (upper left seed)
  97.  Local yi# = yc-yb                ;initial value of y
  98.  Local  x# = 0                    ;maths' x, 
  99.  Local  y# = 0                    ;         y 
  100.  Local sx# = xi                   ;current seed
  101.  Local sy# = yi                   ;            x,y  
  102.  Local xo# = 0 : yo# = 0          ;allow reference to former iteration x or y value
  103.  Local ti# = (bnd*2)/res          ;seeds incrementation
  104.   While sy <= yb
  105.      While sx <= xb                ;seeds forms a grid 
  106.         x = sx : y = sy           ;current seed 
  107.         For i=0 To itr            ;
  108.           xo = x : yo = y         ;remember former value
  109. ;-----------------                ;if you want to experiment with different pics try changing this
  110.           x = xo-t*Sin(deg(Sin(deg(3*yo))+xo)) ;new x value 
  111.           y = yo+t*Sin(deg(Sin(deg(3*xo))+yo)) ;New y value
  112. ;-----------------
  113.           Color (i*i) Mod nbc,(Abs(sx)*i) Mod nbc,(Abs(sy)*i) Mod nbc   ;calculate some color :)
  114. ;          Rect df*x,df*y,1,1      ;draw a point (fast)
  115.          Plot df*x,df*y          ;draw a point 
  116.         Next
  117.         sx=sx+ti                  ;next seed point 
  118.      Wend
  119.      sy=sy+ti                     ;next seed row
  120.      sx=xi                        ;beginning of row
  121.    Wend 
  122. End Function
  123. ;--------------------------------------------------------------------------
  124. Function rad#(deg_ang#)           ;convert degrees to radians
  125.   deg_ang=deg_ang*rad_fac         ;Const rad_fac#=Pi/180
  126.  Return deg_ang
  127. End Function
  128. ;--------------------------------------------------------------------------
  129. Function deg#(rad_ang#)           ;convert radians to degrees 
  130.   rad_ang=rad_ang*deg_fac         ;Const deg_fac#=180/Pi
  131.  Return rad_ang
  132. End Function
  133. ;--------------------------------------------------------------------------